package com.gy.mbaselibrary.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.gy.mbaselibrary.R;
import com.gy.mbaselibrary.utils.ScreenUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

public class LaguageBaseDialog extends Dialog {
    TextView tv_putonghua;
    TextView tv_yingyu;
    TextView tv_quxiao;

    private LaguageListener laguageListener;
    private Object tag;

    public Object getTag() {
        return tag;
    }

    public void setTag(Object tag) {
        this.tag = tag;
    }

    public LaguageBaseDialog(@NonNull Context context) {
        super(context);
        init();
    }

    public LaguageBaseDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        init();
    }

    protected LaguageBaseDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        init();
    }



    private void init() {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_laguage_base,null);
        setContentView(view);

        tv_putonghua = view.findViewById(R.id.tv_putonghua);
        tv_yingyu = view.findViewById(R.id.tv_yingyu);
        tv_quxiao = view.findViewById(R.id.tv_quxiao);

        setCancelable(true);//点击外部不可dismiss
        setCanceledOnTouchOutside(true);
        Window window = this.getWindow();
        window.setGravity(Gravity.BOTTOM);
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = ScreenUtil.getScreenWidth(getContext()) - ScreenUtil.dp2px(16,getContext()) * 2;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(params);
        //window.setBackgroundDrawable(null);
        //设置半透明度
        window.setDimAmount(0.5f);

        tv_putonghua.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (laguageListener != null){
                    laguageListener.laguageListener(0);
                }
            }
        });

        tv_yingyu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (laguageListener != null){
                    laguageListener.laguageListener(1);
                }
            }
        });

        tv_quxiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (laguageListener != null){
                    laguageListener.laguageListener(2);
                }
            }
        });
    }

    public interface LaguageListener{
        void laguageListener(int p1);
    }


    public void setListener(LaguageListener laguageListener) {
        this.laguageListener = laguageListener;
    }
}
